package com.funtonow.jqdk.utils;

import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import com.funtonow.jqdk.R;
import com.funtonow.jqdk.base.SqjAppliaction;

/**
 * Created by zhouyou on 2016/6/28.
 * Class desc: 单例土司
 */
public class ToastUtils {

    private static Toast mToast;

    private static View toastView;

    /**
     * 显示吐司
     *
     * @param message
     */
    public static void show(final String message) {
        if (mToast == null) {
            mToast = Toast.makeText(SqjAppliaction.getContext(), message, Toast.LENGTH_SHORT);
            if (toastView == null) {
                LayoutInflater inflater = LayoutInflater.from(SqjAppliaction.getContext());
                toastView = inflater.inflate(R.layout.toast_view, null);
            }
            setMsg(toastView, message);
            mToast.setView(toastView);
        } else {
            if (toastView == null) {
                LayoutInflater inflater = LayoutInflater.from(SqjAppliaction.getContext());
                toastView = inflater.inflate(R.layout.toast_view, null);
            }
            setMsg(toastView, message);
            mToast.setView(toastView);
        }
        mToast.show();
    }

    private static void setMsg(View view, String message) {
        TextView textView = view.findViewById(R.id.tv_toast);
        textView.setText(message);
    }

}
